package org.jxht.web.api;

import org.jxht.dto.EvaQuestionDto;
import org.jxht.dto.entity.RequestEvaEntity;
import org.jxht.service.impl.StuEvaService;
import org.jxht.util.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评教Controller
 *
 * @anthor huang
 * @Create 2017/5/27
 **/
@Controller
@RequestMapping("JxhtWeb/StuEvaController")
public class StuEvaController {

    @Autowired
    StuEvaService stuEvaService;

    @RequestMapping(value = "/{requestId}/addStuEvaInfo",method = RequestMethod.POST)
    public void addStuEvaInfo(@PathVariable("requestId")String requestId,
                              @RequestParam(value = "requestJson")String requestJson){
         List<RequestEvaEntity> lists = GsonUtil.parseJsonArrayWithGson(requestJson,RequestEvaEntity.class);
         for(RequestEvaEntity entity:lists){
             stuEvaService.insertStuEvaService(entity);
         }
    }

    @RequestMapping(value = "/addEvaluationInfo")
    public void addEvaluationInfo(@RequestParam(value = "requestJson")String requestJson){
        List<EvaQuestionDto> lists = GsonUtil.parseJsonArrayWithGson(requestJson,EvaQuestionDto.class);
        for(EvaQuestionDto dto:lists){
            stuEvaService.insertEvaluationService(dto);
        }
    }

    @RequestMapping(value = "/{requestId}/getStuEvaInfoResultSigln")
    @ResponseBody
    public List getStuEvaInfoResultSigln(@PathVariable("requestId")int requestId){
        RequestEvaEntity entity = new RequestEvaEntity();
        entity.setTeaCouId(requestId);
        return stuEvaService.queryStuEvaService(entity);
    }

    @RequestMapping(value = "/getStuEvaInfoResultAll")
    @ResponseBody
    public List getStuEvaInfoResultAll(){
        RequestEvaEntity entity = new RequestEvaEntity();
        return stuEvaService.queryStuEvaService(entity);
    }

    @RequestMapping(value = "/getEvalutionInfo")
    @ResponseBody
    public List getEvalutionInfo(){
        return stuEvaService.queryEvaluationService();
    }

    @RequestMapping(value = "/{requestId}/deteleEvalutionInfo")
    public void deteleEvalutionInfo(@PathVariable("requestId")long requestId){
        EvaQuestionDto dto = new EvaQuestionDto();
        dto.setEvaId(requestId);
        stuEvaService.deleteEvaluationService(dto);
    }

    @RequestMapping(value = "/{requestId}/deteleStuEvaInfo")
    public void deteleStuEvaInfo(@PathVariable("requestId")int requestId){
        RequestEvaEntity entity = new RequestEvaEntity();
        entity.setTeaCouId(requestId);
        stuEvaService.deleteStuEvaService(entity);
    }
}
